﻿<%@ page import="bean.SupplieroutBean" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="util.JdbcUtil" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="util.Page"%>
<%@ page import="bean.RecordoutBean" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
  <head>
    <title>outbound</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
    <link href="data/styles.css" type="text/css" rel="stylesheet"/>
    <link href="files/outbound/styles.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" href="bootstrap/css/fenye.css">
    <link rel="stylesheet" type="text/css" href="layui/css/laytable.css">
    <script src="bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="resources/scripts/jquery-3.2.1.min.js"></script>
    <script src="resources/scripts/axure/axQuery.js"></script>
    <script src="resources/scripts/axure/globals.js"></script>
    <script src="resources/scripts/axutils.js"></script>
    <script src="resources/scripts/axure/annotation.js"></script>
    <script src="resources/scripts/axure/axQuery.std.js"></script>
    <script src="resources/scripts/axure/doc.js"></script>
    <script src="resources/scripts/messagecenter.js"></script>
    <script src="resources/scripts/axure/events.js"></script>
    <script src="resources/scripts/axure/recording.js"></script>
    <script src="resources/scripts/axure/action.js"></script>
    <script src="resources/scripts/axure/expr.js"></script>
    <script src="resources/scripts/axure/geometry.js"></script>
    <script src="resources/scripts/axure/flyout.js"></script>
    <script src="resources/scripts/axure/model.js"></script>
    <script src="resources/scripts/axure/repeater.js"></script>
    <script src="resources/scripts/axure/sto.js"></script>
    <script src="resources/scripts/axure/utils.temp.js"></script>
    <script src="resources/scripts/axure/variables.js"></script>
    <script src="resources/scripts/axure/drag.js"></script>
    <script src="resources/scripts/axure/move.js"></script>
    <script src="resources/scripts/axure/visibility.js"></script>
    <script src="resources/scripts/axure/style.js"></script>
    <script src="resources/scripts/axure/adaptive.js"></script>
    <script src="resources/scripts/axure/tree.js"></script>
    <script src="resources/scripts/axure/init.temp.js"></script>
    <script src="resources/scripts/axure/legacy.js"></script>
    <script src="resources/scripts/axure/viewer.js"></script>
    <script src="resources/scripts/axure/math.js"></script>
    <script src="resources/scripts/axure/jquery.nicescroll.min.js"></script>
    <script src="data/document.js"></script>
    <script src="files/outbound/data.js"></script>
    <script type="text/javascript">
      $axure.utils.getTransparentGifPath = function() { return 'resources/images/transparent.gif'; };
      $axure.utils.getOtherPath = function() { return 'resources/Other.html'; };
      $axure.utils.getReloadPath = function() { return 'resources/reload.html'; };
    </script>

    <script >
      $(function () {
        $("ul.pagination li.page-item a").click(function () {
          return false;
        });
      });
      function modifysu(soutid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="outboundsumodify?soutid="+soutid;
        }
      }
      function delsu(soutid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="outboundsudelete?soutid="+soutid;
        }
      }
      function modifyre(outid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="outboundremodify?outid="+outid;
        }
      }
      function delre(outid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="outboundredelete?outid="+outid;
        }
      }
    </script>
    <style>
      .cont{
        position: relative;
      }
      .tb1{
        position: absolute;
        top: 50px;
        left: 50px;
      }
      .tb2{
        position: absolute;
        top: 350px;
        left: 50px;
      }
      .tb1 table{
        border-collapse:collapse;
        width: 800px;
      }
      .tb2 table{
        border-collapse:collapse;
        width: 800px;
      }
      #btn{
        position: absolute;
        top: 20px;
        right: 100px;
        width: 70px;
        height: 30px;
        background-color:rgba(0, 121, 254, 0.5);
        border-radius:3px;
        border-width:0px;
        font-family:'微软雅黑', sans-serif;
        font-weight:400;
        font-style:normal;
        font-size:14px;
        color:#FFFFFF;
        line-height:20px;
      }
      td{
        white-space: nowrap;
      }
    </style>
      </head>
  <%
    int start ;//limit的偏移量（从第几条数据开始显示）
    int count =5;//每页显示多少条数据
    //第一次进来start为null会报错，所以用try-catch捕获异常后设置偏移量为0
    try {
      start = Integer.parseInt(request.getParameter("page.start"));
    } catch (Exception e) {
      start = 0;
    }
    int total = 0;//总共多少条数据
    String totalsql = "SELECT COUNT(*) FROM supplier_out";
    try {
      PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(totalsql);
      ResultSet rs = ps.executeQuery(totalsql);
      while (rs.next()) {
        total = rs.getInt(1);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    //页面的工具类，把上面获取的两个值传进去封装一下
    Page page1 = new Page(start, count,total);

    //session保存起来
    session.setAttribute("page", page1);

    //显示表格数据
    String sql ="SELECT * FROM supplier_out ORDER BY soutid desc limit ?,?";
    try {
      PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
      //偏移量和行数就是上面封装起来的
      ps.setInt(1, page1.getStart());
      ps.setInt(2, page1.getCount());
      ResultSet set = ps.executeQuery();
      ArrayList<SupplieroutBean> arr = new ArrayList<SupplieroutBean>();
      while (set.next()){
        SupplieroutBean suo = new SupplieroutBean();
        suo.setSoutid(set.getInt(1));
        suo.setName(set.getString(2));
        suo.setPerson(set.getString(3));
        suo.setOutid(set.getInt(4));
        suo.setEmail(set.getString(5));
        suo.setTel(set.getString(6));
        suo.setAddress(set.getString(7));
        arr.add(suo);
      }
      session.setAttribute("arr", arr);
    } catch (Exception e) {
      e.printStackTrace();
    }
  %>
  <%
    int start2 ;//limit的偏移量（从第几条数据开始显示）
    int count2 =5;//每页显示多少条数据
    //第一次进来start为null会报错，所以用try-catch捕获异常后设置偏移量为0
    try {
      start2 = Integer.parseInt(request.getParameter("page2.start"));
    } catch (Exception e) {
      start2 = 0;
    }
    int total2 = 0;//总共多少条数据
    String totalsql2 = "SELECT COUNT(*) FROM record_out";
    try {
      PreparedStatement ps2 = JdbcUtil.getConnection().prepareStatement(totalsql2);
      ResultSet rs2 = ps2.executeQuery(totalsql2);
      while (rs2.next()) {
        total2 = rs2.getInt(1);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    //页面的工具类，把上面获取的两个值传进去封装一下
    Page page2 = new Page(start2, count2,total2);

    //session保存起来
    session.setAttribute("page2", page2);

    //显示表格数据
    String sqls ="SELECT * FROM record_out ORDER BY outid desc limit ?,?";
    try {
      PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sqls);
      ps.setInt(1, page2.getStart());
      ps.setInt(2, page2.getCount());
      ResultSet set = ps.executeQuery();
      System.out.println(sql.toString());
      ArrayList<RecordoutBean> ar= new ArrayList<RecordoutBean>();
      while (set.next()){
        RecordoutBean reo = new RecordoutBean();
        reo.setOutid(set.getInt(1));
        reo.setWid(set.getInt(2));
        reo.setType(set.getString(3));
        reo.setRname(set.getString(4));
        reo.setPrice(set.getDouble(5));
        reo.setNumber(set.getDouble(6));
        reo.setTime(set.getString(7));
        ar.add(reo);
      }
      session.setAttribute("ar", ar);

    } catch (Exception e) {
      e.printStackTrace();
    }
  %>
  <body>
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u296" class="ax_default box_1">
        <div id="u296_div"  class="cont">

          <div  class="tb1">
            <h1>供应商信息</h1>
            <table  class="layui-table">
              <thead>
              <tr>
                <th>供应商id</th>
                <th>供应商的公司名</th>
                <th>负责人</th>
                <th>货物id</th>
                <th>邮箱</th>
                <th>电话</th>
                <th>地址</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody id="tbody1">
              <c:forEach items="${arr}" var="suo">
                <tr>
                  <td>${suo.soutid}</td>
                  <td>${suo.name}</td>
                  <td>${suo.person}</td>
                  <td>${suo.outid}</td>
                  <td>${suo.email}</td>
                  <td>${suo.tel}</td>
                  <td>${suo.address}</td>
                  <td>
                    <input type="button" value="删除" onclick="delsu(${suo.soutid })" />
                    <input type="button" value="修改" onclick="modifysu(${suo.soutid })" />
                  </td>
                </tr>
              </c:forEach>
              </tbody>

            </table>
            <div>
              <ul class="pagination justify-content-center">
                <%--首页--%>
                <li <c:if test="${!page.hasPreviouse}">class="page-item"</c:if>>
                  <a class="page-link" href="?page.start=0">«</a>
                </li>
                <%--上一页--%>
                <li <c:if test="${!page.hasPreviouse}">class="page-item"</c:if>>
                  <a class="page-link" href="?page.start=${page.start-page.count}">‹</a>
                </li>
                <%--中间页--%>
                <c:forEach begin="0" end="${page.totalPage-1}" varStatus="status">
                  <c:if test="${status.count*page.count-page.start<=30 && status.count*page.count-page.start>=-10}">
                    <li <c:if test="${status.index*page.count==page.start}">class="page-item"</c:if>>
                      <a class="page-link" href="?page.start=${status.index*page.count}"
                         <c:if test="${status.index*page.count==page.start}">class="current"</c:if>
                      >${status.count}</a>
                    </li>
                  </c:if>
                </c:forEach>
                <%--下一页--%>
                <li <c:if test="${!page.hasNext}">class="page-item"</c:if>>
                  <a class="page-link" href="?page.start=${page.start+page.count}">›</a>
                </li>
                <%--尾页--%>
                <li  <c:if test="${!page.hasNext}">class="page-item"</c:if>>
                  <a class="page-link" href="?page.start=${page.last}">»</a>
                </li>
              </ul>
            </div>
          </div>
          <div  class="tb2">
            <h1>货物信息</h1>
            <table  class="layui-table">
              <thead>
              <tr>
                <th>货物id</th>
                <th>仓库id</th>
                <th>货物类型</th>
                <th>货物名称</th>
                <th>货物价格</th>
                <th>出库数量</th>
                <th>出库时间</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody id="tbody2">
              <c:forEach items="${ar}" var="reo">
                <tr>
                  <td>${reo.outid}</td>
                  <td>${reo.wid}</td>
                  <td>${reo.type}</td>
                  <td>${reo.rname}</td>
                  <td>${reo.price}</td>
                  <td>${reo.number}</td>
                  <td>${reo.time}</td>
                  <td>
                    <input type="button" value="删除" onclick="delre(${reo.outid })" />
                    <input type="button" value="修改" onclick="modifyre(${reo.outid })" />
                  </td>
                </tr>
              </c:forEach>
              </tbody>

            </table>
            <div>
              <ul class="pagination justify-content-center">
                <%--首页--%>
                <li <c:if test="${!page2.hasPreviouse}">class="page-item"</c:if>>
                  <a class="page-link" href="?page2.start=0">«</a>
                </li>
                <%--上一页--%>
                <li <c:if test="${!page2.hasPreviouse}">class="page-item"</c:if>>
                  <a class="page-link" href="?page2.start=${page2.start-page2.count}">‹</a>
                </li>
                <%--中间页--%>
                <c:forEach begin="0" end="${page2.totalPage-1}" varStatus="status">
                  <c:if test="${status.count*page2.count-page2.start<=30 && status.count*page2.count-page2.start>=-10}">
                    <li <c:if test="${status.index*page2.count==page2.start}">class="page-item"</c:if>>
                      <a class="page-link" href="?page2.start=${status.index*page2.count}"
                         <c:if test="${status.index*page2.count==page2.start}">class="current"</c:if>
                      >${status.count}</a>
                    </li>
                  </c:if>
                </c:forEach>
                <%--下一页--%>
                <li <c:if test="${!page2.hasNext}">class="page-item"</c:if>>
                  <a class="page-link" href="?page2.start=${page2.start+page2.count}">›</a>
                </li>
                <%--尾页--%>
                <li  <c:if test="${!page2.hasNext}">class="page-item"</c:if>>
                  <a class="page-link" href="?page2.start=${page2.last}">»</a>
                </li>
              </ul>
            </div>
          </div>
        </div>
        </div>
        <div id="u296_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u297" class="ax_default _文本段落">
        <div id="u297_div" class=""></div>
        <div id="u297_text" class="text ">
          <p><span>出库管理</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u298" class="ax_default box_1">
        <div id="u298_div" class=""></div>
        <div id="u298_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u299" class="ax_default _图片_">
        <img id="u299_img" class="img " src="images/customer/u152.svg"/>
        <div id="u299_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u300" class="ax_default label">
        <div id="u300_div" class=""></div>
        <div id="u300_text" class="text ">
          <p><span>列表</span></p>
        </div>
      </div>


      <!-- Unnamed (矩形) -->
      <div id="u303" class="ax_default box_1">
        <div id="u303_div" class=""></div>
        <div id="u303_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u304" class="ax_default box_1">
          <button id="btn" onclick="seek()" >筛选</button>
        </div>
      </div>
      <!-- Unnamed (矩形) -->
      <div id="u306" class="ax_default box_1">
        <div id="u306_div" class=""></div>
        <div id="u306_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图片 ) -->
      <div id="u307" class="ax_default _图片_">
        <img id="u307_img" class="img " src="images/customer/u149.png"/>
        <div id="u307_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u308" class="ax_default label">
        <div id="u308_div" class=""></div>
        <div id="u308_text" class="text ">
          <p><span>筛选</span></p>
        </div>
      </div>

      <!-- Unnamed (文本框) -->
      <div id="u309" class="ax_default text_field">
        <div id="u309_div" class=""></div>
        <input id="u309_input" type="text" value="" class="u309_input"/>
      </div>

      <!-- Unnamed (文本框) -->
      <div id="u310" class="ax_default text_field">
        <div id="u310_div" class=""></div>
        <input id="u310_input" type="text" value="" class="u310_input"/>
      </div>


      <!-- Unnamed (组合) -->
      <div id="u313" class="ax_default" data-left="126" data-top="252" data-width="121" data-height="35">

        <!-- Unnamed (矩形) -->
        <div id="u314" class="ax_default box_1">
          <div id="u314_div" class=""></div>
          <div id="u314_text" class="text " style="display:none; visibility: hidden">
            <p></p>
          </div>
        </div>

        <!-- Unnamed (图片 ) -->
        <div id="u315" class="ax_default _图片_">
          <img id="u315_img" class="img " src="images/administrator/u218.png"/>
          <div id="u315_text" class="text " style="display:none; visibility: hidden">
            <p></p>
          </div>
        </div>

        <!-- Unnamed (矩形) -->
        <div id="u316" class="ax_default label">
          <div id="u316_div" class=""></div>
          <div id="u316_text" class="text ">
            <p><span>添加</span></p>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
      function seek() {
        var seeksupplierout = $("#u309_input").val();
        var seekrecordout = $("#u310_input").val();
        console.log(seeksupplierout+"and"+seekrecordout)
        //判断是否需要重新查询
        if(seeksupplierin=="客户"&&seekrecordin=="入库货物"){
          location.href="outbound.jsp"
        }else {
          $.ajax({
            url : "outboundhunt?seeksupplierout="+seeksupplierout+"&seekrecordout="+seekrecordout,//提交地址
            type : "post",//提交方式（get,post）
            dataType : "json",//指定服务器返回的数据类型
            success : function(data) {//请求成功后的回调函数
              console.log(data)
              $("#tbody1").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
              var trStr = "";
              for (var i = 0; i < data.length; i++) {
                trStr += "<tr><td>" + data[i].soutid +
                        "</td><td>" + data[i].name +
                        "</td><td>" + data[i].person +
                        "</td><td>" + data[i].outid +
                        "</td><td>" + data[i].email +
                        "</td><td>" + data[i].tel +
                        "</td><td>" + data[i].address +
                        "</td><td>" +  "<input type='button' value='删除' onclick='del(${suo.soutid })' />" +
                        "<input type='button' value='修改' onclick='modifysu(${suo.soutid })' />" +
                        "</td></tr>"
              }
              $("#tbody1").show().append(trStr);//向<tbody>内部追加内容
              //货物表
              $("#tbody2").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
              var trStr2 = "";
              for (var i = 0; i < data.length; i++) {
                trStr2 += "<tr><td>" + data[i].outid +
                        "</td><td>" + data[i].wid +
                        "</td><td>" + data[i].type +
                        "</td><td>" + data[i].rname +
                        "</td><td>" + data[i].price +
                        "</td><td>" + data[i].number +
                        "</td><td>" + data[i].time +
                        "</td><td>" +  "<input type='button' value='删除' onclick='delre(${reo.outid })' />" +
                        "<input type='button' value='修改' onclick='modifyre(${reo.outid })' />" +
                        "</td></tr>"
              }
              $("#tbody2").show().append(trStr2);//向<tbody>内部追加内容向<tbody>内部追加内容

            },
            error : function() {
              alert('请求失败');
            }
          });


        }
      }
    </script>
    <script src="resources/scripts/axure/ios.js"></script>
  </body>
</html>
